using System.Collections.Generic;
using DL.Tools;
using JetBrains.Annotations;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace DL.UIBinding
{
    /// <summary>
    /// 轮播图组件
    /// </summary>
    public class CarouselView : UIBehaviour
    {
        public enum MovementType
        {
            /// <summary>
            /// 循环
            /// </summary>
            Circulation, //循环，轮播到最后一页之后，直接回到第一页

            /// <summary>
            /// 来回往复
            /// </summary>
            PingPong, //来回往复，轮播到最后一页之后，倒序轮播，到第一页之后，同理
        }
        public enum Direction
        {
            /// <summary>
            /// From the left to the right
            /// </summary>
            LeftToRight,

            /// <summary>
            /// From the right to the left
            /// </summary>
            RightToLeft,

            /// <summary>
            /// From the bottom to the top.
            /// </summary>
            BottomToTop,

            /// <summary>
            /// From the top to the bottom.
            /// </summary>
            TopToBottom,
        }
        
        [SerializeField]
        private RectTransform m_Content;
        [SerializeField]
        private RectTransform m_ViewPortRT;
        
        [SerializeField] 
        private MovementType m_Movement = MovementType.Circulation;
        [SerializeField] 
        private Direction m_Direction = Direction.LeftToRight;

        [SerializeField] private RectTransform m_ItemPrefab;
        
        // 圆圈页码ToggleGroup
        private ToggleGroup m_ToggleGroup;
        // 圆圈页码Toggle
        private List<Toggle> m_ToggleList;
        //以Toggle为Key，返回页码
        private Dictionary<Toggle, int> m_TogglePageMap;

        // Item间隔
        [SerializeField]
        private Vector2 m_Spacing;
        [SerializeField] private bool m_IsLoop;
        [SerializeField] private float m_LoopStep = 2f;
        [SerializeField] private bool m_AllowDrag;//手动拖动
        
        [SerializeField,Header("轮播动画时间")]
        private float m_SwipeTime = 0.5f;
        private bool m_IsInit;
        
        //标准Item Rect
        private Rect m_ItemRect;
        private RectTransform m_TempRect;
        private Rect m_WorldRect;
        
        private List<float> m_ChildItemPosition;
        private ICarouselCollection<CarouselContext> m_Collection;
        
        public void Init([NotNull]ICarouselCollection<CarouselContext> coll)
        {
           if(m_IsInit) return;
           //计算数据的位置 
           m_Collection = coll;
            
           Transform go = new GameObject("Standard Item").transform;
           go.SetParent(m_Content);
           m_TempRect = go.gameObject.AddComponent<RectTransform>();
           var rect = m_ItemPrefab.rect;
           m_TempRect.sizeDelta = new Vector2(rect.width, rect.height);
           // 设置m_TempRect的锚点为左下角（0,1），这意味着它将相对于其父对象的左下角定位
           m_TempRect.anchorMin = new Vector2(0, 1);
           m_TempRect.anchorMax = new Vector2(0, 1);
	        
           m_ItemRect = m_ItemPrefab.GetComponent<RectTransform>().rect;
        
           m_WorldRect = GetComponent<RectTransform>().WorldRect();
        }


        public void SeekToTargetItem(int index)
        {
            
        }

        public void OnNextPageClick()
        {
            
        }

        public void OnPrePageClick()
        {
            
        }

        public void ChangeAxisType()
        {
            
        }
    }
}
